<template>
  <div class="login_M">
    <head-view></head-view>
    <div class="page-container">
      <h1>LOGIN</h1>
      <div class="form-container">
        <input v-model="msg.i_user" placeholder="Username" />
        <br />
        <input placeholder="Password" v-model="msg.i_pass" type="password" />
        <br />
        <button v-on:click="check">Sign me in</button>
      </div>
      <div class="connect">
        <span>No registration?</span>
        <router-link to="/register"
          ><button class="register">Register</button></router-link
        >
      </div>
    </div>
  </div>
</template>
<script>
import api from "@/fetch/api";
export default {
  name: "Test",
  data() {
    return {
      username: [],
      password: [],
      h:0,
      login_root: false,
      msg: {
        i_user: "",
        i_pass: "",
      },
    };
  },
  methods: {
    //核对输入的账号密码
    check() {
      api.login(this.msg.i_user, this.msg.i_pass).then(
        (res) => {
          switch (res.code) {
            case "200":
              //将服务器返回的token放入store中
              this.$store.commit("login", res.token);
              console.log(res);
              this.$router.push("/");
              break;
            case "401":
              console.log("err401");
              this.err = true;
              break;
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
  },
};
</script>
<style scoped>
* {
   margin: 0;padding: 0;list-style: none;border: none;
}
.login_M {
  width: 100%;
  height: 100%;
  background-image: url("../assets/img/back03.jpg");
  background-attachment: fixed;
  background-size: cover;
  position: fixed;
}
.page-container {
  margin: 120px auto 0 auto;
}
.form-container {
  position: relative;
  width: 305px;
  margin: 15px auto 0 auto;
  text-align: center;
}
input {
  width: 270px;
  height: 42px;
  margin-top: 25px;
  padding: 0 15px;
  background: #2d2d2d; /* browsers that don't support rgba */
  background: rgba(45, 45, 45, 0.15);
  -moz-border-radius: 6px;
  -webkit-border-radius: 6px;
  border-radius: 6px;
  border: 1px solid #3d3d3d; /* browsers that don't support rgba */
  border: 1px solid rgba(255, 255, 255, 0.15);
  -moz-box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.1) inset;
  -webkit-box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.1) inset;
  box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.1) inset;
  font-family: "PT Sans", Helvetica, Arial, sans-serif;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
input:-moz-placeholder {
  color: #e0d1d1;
}
input:-ms-input-placeholder {
  color: #e0d1d1;
}
input::-webkit-input-placeholder {
  color: #e0d1d1;
}
button {
  cursor: pointer;
  width: 300px;
  height: 44px;
  margin-top: 25px;
  padding: 0;
  background: #730baf;
  -moz-border-radius: 6px;
  -webkit-border-radius: 6px;
  border-radius: 6px;
  border: 1px solid #730baf;
  -moz-box-shadow: 0 15px 30px 0 rgba(255, 255, 255, 0.25) inset,
    0 2px 7px 0 rgba(0, 0, 0, 0.2);
  -webkit-box-shadow: 0 15px 30px 0 rgba(255, 255, 255, 0.25) inset,
    0 2px 7px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 0 15px 30px 0 rgba(255, 255, 255, 0.25) inset,
    0 2px 7px 0 rgba(0, 0, 0, 0.2);
  font-family: "PT Sans", Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #e0d1d1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.register {
  width: 100px;
  height: 50px;
}
.connect {
  color: #e0d1d1;
  width: 305px;
  margin: 35px auto 0 auto;
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.connect span {
  padding-right: 20px;
}
</style>